<template>
  <div id="app" ref="wrapper1">
    <keep-alive>
      <transition v-if="$route.meta.KeepAlive" :name="transition"><router-view class="router-view wrapper fs10" ref="wrapper"> </router-view></transition>
    </keep-alive>
    <transition v-if="!$route.meta.KeepAlive" :name="transition"><router-view class="router-view wrapper fs10" ref="wrapper"> </router-view></transition>
    <!-- <nut-drag direction="y" :style="{ right: '0px', top: '50px' }">
      <nut-fixednav active-text="快速导航" un-active-text="快速导航" :nav-list="navList" @selected="selected"> </nut-fixednav>
    </nut-drag> -->
  </div>
</template>

<script>
import '../static/css/common.css'
import { windowClose } from '@/utils/closeZLB'
import router from './router'
import DevicePixelRatio from './utils/DevicePixeRatio'
import { getwxAppletUser, getFRSSOToken, getuserRelManyBiz, getUserName, changeApp } from './utils/api'
import { mapState } from 'vuex'
import suspenPopup from './components/NewZzd/public/suspenPopup.vue'
export default {
  name: 'App',
  data() {
    return {
      baseURL: 'https://nfzjszlb.jst.zj.gov.cn/tyzcpt/',
      DanDianName: '',
      logining: false,
      myActive: false,
      gotoPath: '',
      navList: [
        {
          id: 1,
          text: '首页',
          icon: 'https://img11.360buyimg.com/imagetools/jfs/t1/117646/2/11112/1297/5ef83e95E81d77f05/daf8e3b1c81e3c98.png'
        },
        {
          id: 2,
          text: '保存',
          icon: '../static/imgs/app/baocun.png'
        },
        {
          id: 3,
          text: '提交',
          icon: '../static/imgs/app/tijiao.png'
        }
      ],
      visible: false,
      userId: '',
      scroll: '',
      loginStyle: '',
      systemname: '',
      DanDianName: {},
      browseTime: 0, // 浏览时长初始值为 0
      clearTimeSet: null,
      //当前登录的是法人还是个人
      isPer: 1,
      UUID: '',
      ruleForm: {
        username: '',
        password: ''
      },
      //杭州坐标 默认杭州 防止埋点失败
      buryPointParams: ['120.15', '30.28', 1, '05d46fe0a0d84719bc0f82024b0c88cd', '浙里办账号登录'],
      rules: {
        username: [{ required: true, message: '请输入账号', trigger: 'blur' }]
      },
      checked: true
    }
  },
  computed: {
    ...mapState({
      routerDirection: (state) => state.routerDirection
    }),
    transition() {
      if (!this.routerDirection) return 'slide-normal'
      // console.log(this.routerDirection, 'hezhilong')
      return `slide-${this.routerDirection}`
    }
  },
  methods: {
    selected(data){
      if(data.item.text == '首页'){
        this.$router.push({
          path: '/mytodolist'
        })
      }
    },
    getUSERType() {
      let me = this
      ZWJSBridge.getUserType()
        .then((result) => {
          // console.log(result, '=================================result')
          const { userType } = result
          this.isPer = userType
          window.localStorage.setItem('isPer', this.isPer)
          me.Logins()
        })
        .catch((error) => {
          // console.log(error, '======================================error')
          this.isPer = 2
        })
    },
    getUIStyle() {
     
    },
    //清空cookie
    delCookie() {
      var cookies = document.cookie.split(';')
      for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i]
        var eqPos = cookie.indexOf('=')
        var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie
        document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'
      }
      if (cookies.length > 0) {
        for (var i = 0; i < cookies.length; i++) {
          var cookie = cookies[i]
          var eqPos = cookie.indexOf('=')
          var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie
          var domain = location.host.substr(location.host.indexOf('.'))
          document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=' + domain
        }
      }
    },
    setPoints(data, data1) {
      const zwlog = new ZwLog({
        _user_id: data.userid,
        _user_nick: data.username
      })
      zwlog.onReady(function () {
        zwlog.sendPV({
          miniAppId: '2001905684',
          Page_duration: '10s',
          t2: '1.2s',
          t0: '0.2s',
          miniAppName: '粤政易',
          log_status: window.localStorage.getItem('token') ? '02' : '01'
        })
        // zwlog.record('yourTrackerEventCode', 'CLK', { Test1: '测试参数 1' })
        let { metaInfo } = zwlog
      })
    },
    judgeUserCitys: async function () {
      try {
        const res = await getuserRelManyBiz(window.localStorage.getItem('userName1'))
        window.sessionStorage.setItem('UserCityCode', res.data.data)
        if ((res.data.code == 200 && res.data.data.length == 1) || !res.data.data) {
          this.$router.push({
            path: '/ZLJIndex'
          })
        } else if (res.data.code == 200 && res.data.data.length != 1) {
          this.$router.push({
            path: '/citySelect'
          })
        }
      } catch (err) {
        this.$router.push({
          path: '/ZLJIndex'
        })
      }
    },
    CheckIsAndroid() {
      const sUserAgent = window.navigator.userAgent.toLowerCase()
      //支付宝
      const bIsAlipayMini = sUserAgent.indexOf('miniprogram') > -1 && sUserAgent.indexOf('alipay') > -1
      const isweixin = sUserAgent.indexOf('miniprogram') > -1 && sUserAgent.indexOf('wx289ade03af020941') > -1
      const isAPP = sUserAgent.indexOf('zlb_') > -1
      // js中如下判断
      if (!bIsAlipayMini && !isAPP) {
        // 在微信小程序中打开
        // console.log(isAPP, bIsAlipayMini, 'bIsAlipayMinibIsAlipayMinibIsAlipayMinibIsAlipayMini')
        window.sessionStorage.setItem('showBg1', true)
        window.sessionStorage.setItem('showBg2', true)
      } else if (bIsAlipayMini) {
        window.sessionStorage.setItem('isZFB', true)
      } else {
        window.sessionStorage.setItem('isAndroid', true)
      }

      // console.log(sUserAgent, bIsAlipayMini, 'bIsAlipayMinibIsAlipayMini')
      // var browser = {
      //   versions: (function () {
      //     var u = navigator.userAgent,
      //       app = navigator.appVersion
      //     return {
      //       //移动终端浏览器版本信息
      //       ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
      //       android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器 //u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
      //       iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
      //       iPad: u.indexOf('iPad') > -1 //是否iPad
      //     }
      //   })()
      // }
      // if (browser.versions.android) {
      //   window.sessionStorage.setItem('isAndroid', true)
      // } else {
      //   window.sessionStorage.setItem('isAndroid', false)
      // }
    },
    //微信 app 支付宝三端统一登录
    
  },
  mounted() {
    var me = this
    this.getUIStyle()
    // this.getUSERType()
    console.log(processENV,'processENV')
    console.log(processENV1,'process')
    // if (window.localStorage.getItem('userId1')) {
    //   this.setPoints2(window.localStorage.getItem('userId1'), window.localStorage.getItem('DanDianName'))
    // }
    this.CheckIsAndroid()
    //监听浏览器的返回事件
    if (window.history && window.history.pushState) {
      window.history.pushState(null, null, document.URL)
      window.addEventListener('popstate', this.back, false)
    }
  },
  destroyed() {
    window.removeEventListener('popstate', this.back, false)
  },
  created() {
    // 监听返回键
    window.addEventListener('popstate', async () => {
      if (['/', '/view/home', '/401', '/404', '500'].indexOf(this.$route.path) !== -1) {
        const res = await windowClose()
      }
    })
  },
  components: {
    suspenPopup
  }
}
</script>

<style lang="scss">
* {
  margin: 0;
  padding: 0;
}

#app {
  font-family: 'Helvetica Neue', Helvetica, STHeiTi, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-overflow-scrolling: touch;
  /*text-align: center;*/
  color: #2c3e50;
  // position: relative;
  width: 100%;
  height: 100%;

  /*font-size: 14px;*/
  .router-view {
    // position: absolute;
    // overflow-x: hidden;
    // overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transition: all 500ms cubic-bezier(0.55, 0, 0.1, 1);
    backface-visibility: hidden;
    // background-color: #f0f0f0;
  }

  /* 路由切换动画 */
  .slide-forward-enter,
  .slide-back-leave-active {
    opacity: 0;
    transform: translate3d(100%, 0, 0);
  }

  .slide-forward-leave-active,
  .slide-back-enter {
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
  }

  .slide-normal {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }

  .slide-normal-leave-active {
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
  }

  // button {
  //   min-width: 200px;
  //   height: 50px;
  //   line-height: 50px;
  //   text-align: center;
  //   background-color: #fff;
  // }
  .df-c,
  .df-col-c {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .df-col-c {
    flex-direction: column;
  }
}

.mint-popup-bottom {
  left: 0 !important;
  -webkit-transform: initial !important;
}
.nut-fixednav .fixed-btn{
  background: linear-gradient(135deg,#2c68ff 0%,#2c68ff 100%) !important;
  //透明度
  opacity: 0.9;
}
</style>
